/*
 * CameraPreview.cpp
 *
 *  Created on: Jun 24, 2011
 *      Author: MongKieu
 */

#include "../inc/Ui/CameraPreview.h"


using namespace Osp::Media;

CameraPreview::CameraPreview(void) {
}

CameraPreview::~CameraPreview(void) {
	Terminate();
}

result CameraPreview::StartPreview(
		const Osp::Graphics::BufferInfo* pBufferInfo) {
	result r = E_SUCCESS;
	r = Camera::StartPreview(pBufferInfo, false);
	return r;
}

result CameraPreview::StopPreview(void) {
	result r = E_SUCCESS;
	Osp::Media::CameraState state = GetState();
	if (state == CAMERA_STATE_PREVIEW) {
		Camera::StopPreview();
	}
	r = Osp::System::PowerManager::KeepScreenOnState(false, true);
	return r;
}
result CameraPreview::Initialize(void) {
	result r = E_SUCCESS;
	AppLog("Enter.");

	if (!IsPoweredOn()) {
		r = PowerOn();
		if (IsFailed(r)) {
			AppLog("Power on of camera failed.");
			return r;
		}
	}

	return r;
}

result CameraPreview::Terminate(void) {
	result r = E_SUCCESS;
	if (IsPoweredOn()) {
		this->StopPreview();

		r = PowerOff();
		if (IsFailed(r)) {
			AppLog("Power off of camera failed.");
			return r;
		}
	}

	return r;
}
